package com.lr.springbootdemo.repositories;

import com.lr.springbootdemo.bean.Constants;
import com.lr.springbootdemo.bean.People;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * .
 * Created by li.rui on 2016-06-21.
 */
@Repository
public interface PeopleRepository extends CrudRepository<People,Integer> {
    String cache_key_prefix = Constants.CACHE_KEY_PREFIX + "com.lr.springbootdemo.repositories.";

    List<People> findByNameAndSex(String name, String sex);

    @Override
    @Cacheable(value = Constants.CACHE_NAME,key =  "'"+cache_key_prefix+"people_' + #p0")
    People findOne(Integer id);

    @Override
    @CachePut(value = Constants.CACHE_NAME,key = "'"+cache_key_prefix+"people_' + #p0.getId()")
    People save(People people);
}
